package com.theme.passport.controller.sys;

import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.view.R;
import com.theme.passport.entity.theme.AlbumEntity;
import com.theme.passport.service.theme.AlbumService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;



/**
 * 专题
 *
 * @author live
 * @email 870459550@qq.com
 * @date 2023-02-28 10:01:58
 */
@RestController
@RequestMapping("sys/album")
public class SysAlbumController {

    @Autowired
    private AlbumService albumService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:album:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = albumService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:album:info")
    public R info(@PathVariable("id") Long id){
		AlbumEntity album = albumService.getById(id);

        return R.ok().put("album", album);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:album:save")
    public R save(@RequestBody AlbumEntity album){
        album.setCreated(new Date());
        albumService.save(album);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:album:update")
    public R update(@RequestBody AlbumEntity album){
        album.setUpdated(new Date());
        albumService.updateById(album);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:album:delete")
    public R delete(@RequestBody Long[] ids){
        albumService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
